/*
 * GaussianModel.cpp
 *
 *  Created on: Apr 11, 2010
 *      Author: Soheil Damangir
 */

#include "GaussianModel.h"
#include <iostream>
#include "log.h"
using kthrobot::Log;
namespace Group5{

GaussianModel::GaussianModel(int*_mu, int*_iSigma, const int&dimension):dim(dimension) {
  mu = new int[dim];
  iSigma = new int[dim*dim];
  int i;
  for(i=0;i<dim;++i)
  {
    mu[i] = mu[i];
  }
  for(i=0;i<dim*dim;++i)
  {
    iSigma[i] = iSigma[i];
  }
  print();
}

GaussianModel::GaussianModel(std::istream&is)
{
  is >> dim;
  mu = new int[dim];
  iSigma = new int[dim*dim];
  int i;
  for(i=0;i<dim;++i)
  {
    is >> mu[i];
  }
  for(i=0;i<dim*dim;++i)
  {
    is >> iSigma[i];
  }
}
void GaussianModel::print()
{
  int i;
  std::cout << "-----------\n";
  for(i=0;i<dim;++i)
  {
    std::cout << mu[i] << "\t";
  }
  for(i=0;i<dim*dim;++i)
  {
    if (i%dim == 0)
      std::cout << "\n";
    std::cout << iSigma[i] << "\t";
  }
  std::cout << "\n-----------\n";
}

int GaussianModel::confidence(const int*p)
{
  int conf = 0,i,j;
  int nP[dim];
  for (i=0;i<dim;++i)
  {
    nP[i] = p[i]-mu[i];
  }
  for (j=0;j<dim;++j)
  {
    for (i=0;i<dim;++i)
    {
      conf += nP[j]*nP[i]*iSigma[j*dim+i];
    }
  }

  return conf;
}

GaussianModel::~GaussianModel()
{
  delete []mu;
  delete []iSigma;
}

}
